﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;
using System.Web;

namespace LocalCronjob
{
	public class cronjob
	{
		ArrayList _times = new ArrayList();
		private string _name;
		private string _link;
		DateTime lastCall = new DateTime(2000, 1, 1);
		MainForm __mf;
		
		public cronjob(string name, string link, ArrayList times, MainForm mf)
		{
			_name = name;
			_link = link;
			_times = times;
			__mf = mf;
		}
		
		public void Execute()
		{
			__mf.addLog("Execute Cronjob ("+_name+")");
			__mf.navTo(_link);
			lastCall = DateTime.Now;
		}
		
		public void SaveCronjob()
		{
			StreamWriter sw = new StreamWriter(_name+".cj");
			sw.WriteLine(_name);
			sw.WriteLine(_link);
			foreach(DateTime dt in _times)
			{
				sw.WriteLine(dt.Hour+","+dt.Minute);
			}
			sw.Close();
		}
		
		public void RemoveCronjob()
		{
			
		}
		
		public string Name
		{
			get{return _name;}
			set{_name = value;}
		}
		
		public string Link
		{
			get{return _link;}
			set{_link = value;}
		}
		
		public ArrayList Times
		{
			get{return _times;}
		}
		
		public DateTime LastCall
		{
			get{return lastCall;}
		}
	}
}
